<template>
  <el-dialog :close-on-click-modal="closeModal" :visible.sync="form_detail_drawer.formVisible" :title="form.name + '的详情'" width="45%" :before-close="handleClose">
    <el-form ref="ruleForm" :rules="rules" class="demo-ruleForm" :inline="true" :model="form" label-width="180px">
      <el-form-item label="评审类别" prop="category">
        <el-input v-model="form.category" :disabled="disabled" style="width: 15vw" placeholder="请输入评审类别" />
      </el-form-item>
      <el-form-item label="专家库" prop="databaseId">
        <el-select v-show="!disabled" v-model="form.databaseId" :disabled="disabled" placeholder="请选择专家库" style="width: 15vw">
          <el-option v-for="item in tableData.list" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <el-input v-show="disabled" v-model="form.databaseName" :disabled="disabled" style="width: 15vw" />
      </el-form-item>
      <el-form-item label="身份证" prop="identityCard">
        <el-input v-model="form.identityCard" :disabled="disabled" style="width: 15vw" placeholder="请输入身份证" />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="form.name" :disabled="disabled" style="width: 15vw" placeholder="请输入姓名" />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input v-model="form.phone" :disabled="disabled" style="width: 15vw" placeholder="请输入电话" />
      </el-form-item>
      <el-form-item label="职务" prop="post">
        <el-input v-model="form.post" :disabled="disabled" style="width: 15vw" placeholder="请输入职务" />
      </el-form-item>
      <el-form-item label="所学专业" prop="profession">
        <el-input v-model="form.profession" :disabled="disabled" style="width: 15vw" placeholder="请输入专家库名称" />
      </el-form-item>
      <el-form-item label="职业资格" prop="professionalTitle">
        <el-input v-model="form.professionalTitle" :disabled="disabled" style="width: 15vw" placeholder="请输入执业资格" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleClose">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { expertApi } from '@/api/expert'
export default {
  name: 'Dialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    closeModal: {
      type: Boolean,
      default: true
    },
    disabled: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '新增'
    },
    getList: {
      type: Function,
      default: null
    },
    dataSource: Object
  },
  data() {
    return {
      form_detail_drawer: {
        formVisible: false
      },
      tableData: {
        list: []
      },
      postForm: {
        currentPage: 1,
        pageSize: 999
      },
      rules: {
        category: [{ required: true, message: '请输入评审类别', trigger: 'blur' }],
        databaseId: [{ required: true, message: '请选择专家库', trigger: 'blur' }],
        identityCard: [{ required: true, message: '请输入身份证', trigger: 'blur' }],
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入电话', trigger: 'blur' }],
        post: [{ required: true, message: '请输入职务', trigger: 'blur' }],
        profession: [{ required: true, message: '请输入专家库名称', trigger: 'blur' }],
        professionalTitle: [{ required: true, message: '请输入职业资格', trigger: 'blur' }]
      }
    }
  },
  computed: {
    form: function () {
      return this.dataSource
    }
  },
  watch: {
    visible(newVal, oldVal) {
      this.form_detail_drawer.formVisible = newVal
      this.loadExpertData(this.postForm)
    }
  },
  created() {},
  methods: {
    // 获取专家库列表
    loadExpertData(postForm) {
      expertApi.loadExpert(postForm).then(res => {
        const { data, msg, result } = res
        if (result === 1) {
          this.tableData.list = data.list
          this.tableData.total = data.total
        } else if (result === 0) {
          this.$message.warning(msg)
          this.tableData.list = []
          this.tableData.total = 0
        }
      })
    },
    // 确定
    submit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          // 校验通过
          expertApi.submitExpertInfo(this.$filNull(this.form)).then(res => {
            const { result, msg, data } = res
            if (result == 1) {
              this.$message.success(msg)
              this.getList(this.postForm)
              this.handleClose()
            } else {
              this.$message.warning(msg)
              // this.handleClose()
            }
          })
        } else {
          console.log('校验未通过')
          return false
        }
      })
    },
    // 取消   关闭弹窗
    handleClose() {
      this.$emit('close')
    }
  }
}
</script>

<style lang="suss" scoped></style>
